<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Admin\Lianggoods;
use App\Admin\Daren;
use App\Admin\Categoods;
use App\Admin\GetCategory;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;

class DarenController extends Controller
{
    //达人列表显示
    public function darenshow(Request $request){
        $daren=DB::table('daren')->leftJoin('users','daren.users_id','=','users.id')
            ->get()->toArray();
//        dd($daren);
        return view('admin/daren/DarenList',compact('daren'));
    }
    //添加达人
    public function darenadd(){
        $da = DB::table('users')->get()->toArray();
//        dd($da);
        return view('admin/daren/DarenAdd',['da'=>$da]);
    }
    public function darenadddata(Request $request){

        $input = $request->all();
        $id=$input['users_id'];
        $da =DB::table('daren')->where('users_id',$id)->get()->toArray();
        if($da){
            return back();
        }
        $res = Daren::create($input);
        return redirect('admin/DarenList');
    }
//    删除达人
    public function darendel(Request $request){
        $id=$_GET['id'];
        $da =DB::table('daren')->where('users_id',$id)->delete();
        return redirect('admin/DarenList');
    }
}
